<template>
  <div>
    <el-row :gutter="20" class="nav">
      <el-col :offset="12" :span="3" class="login">
        <span v-if="$store.state.name"
          >欢迎{{ $store.state.name }}
          <button @click="exit">退出登陆</button></span
        >
        <span v-else @click="login = true">登陆</span>
      </el-col>
      <el-col :span="9">
        <el-menu
          class="el-menu-demo"
          mode="horizontal"
          background-color="#545c64"
          text-color="#fff"
          router
        >
          <el-menu-item index="1">我的订单</el-menu-item>

          <el-menu-item index="/collection">我的收藏</el-menu-item>
          <el-menu-item index="/shopcar">购物车</el-menu-item>
        </el-menu></el-col
      >
    </el-row>
    <div class="con">
      <el-menu
        class="el-menu-demo"
        mode="horizontal"
        text-color="#545c64"
        router
      >
        <el-menu-item index="/home">首页</el-menu-item>

        <el-menu-item index="/shop">全部商品</el-menu-item>
        <el-menu-item index="4">关于我们</el-menu-item>
      </el-menu>
      <div>
        <router-view></router-view>
      </div>
    </div>

    <el-dialog title="登陆" :visible.sync="login">
      <el-form :model="form">
        <el-form-item label="用户名">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.pass" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="login = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      login: false,
      form: {
        name: "",
        pass: "",
      },
    };
  },
  methods: {
    submit() {
      this.login = false;
      this.$axios
        .post("/users/login", {
          userName: this.form.name,
          password: this.form.pass,
        })
        .then((res) => {
          console.log(res);
          if (res.data.code == "001") {
            this.$store.commit("setuser", this.form.name);
            this.login = false;
          }
        });
    },
    exit() {
      this.$store.commit("exit");
    },
  },
  modules: {},
};
</script>
<style lang="scss">
.nav {
  background: #545c64;
}
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  height: 60px;
}
.con {
  width: 1000px;
  margin: 0 auto;
  border-bottom: 1px solid #ccc;
}
button {
  color: #545c64;
}
</style>
